require 'open-uri'

CONSTANT = 'http://knusys6.knu.ac.kr/knu/owa3/sylla_f.lst?t_gubun=3&t_query1=1'

# test yielder 
def linkYielder(uri)
  open(uri) do |f|
    number = 1
    f.each do |line|
      regex = Regexp.new(/<a[^>]*href="([^"]*)"[^>]*>/i)
      matchdata = regex.match(line)
      while matchdata
        yield matchdata[1]
        line = matchdata.post_match
        matchdata = regex.match(line)
      end
    end
  end  
end

# it is not clear the determining way wheater absolute address or relative address
def absoluteLinkYielder(uri)
  linkYielder(uri) do |output|
    absolute = output =~/http/ 
    yield output if absolute
    yield uri[0,uri.rindex('/')+1]+output unless absolute
  end
end

#absoluteLinkYielder('http://www.google.co.kr/search?complete=1&hl=ko&newwindow=1&q=regex+tester&btnG=%EA%B2%80%EC%83%89&lr=&aq=f&oq=') do |link|
absoluteLinkYielder(CONSTANT) do |link|
  print link ,"\n"
end